<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="./font_3366928_6aytrri25q9/iconfont.css">
  <link rel="stylesheet" href="./flexible.js">

  <script src="./js/jquery.min.js"></script>
  <link rel="stylesheet" href="./css/省钱控.css">


</head>

<style>

</style>

<body>

  <h3>
    <span class="back"><</span>

      省钱控 - 最新优惠
    <i class="iconfont icon-xiazai"></i>
  </h3>

  <ul class="ko">
    <!-- <li>
            <img src="../瀑布流/1.jpg">
            <h4>移动端凑单品：海天 纤维 生抽 1.28了<span>1.09元</span></h4>
          <div class="di">京东商城|10-25 14：20</div><span class="s">12-12-1</span>
          <div class="di2">有人评论</div>
    
        </li> -->

  </ul>

  <div class="bb">
    <button class="bu1">上一页</button>

    <select>

      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="7">7</option>
      <option value="8">8</option>
      <option value="9">9</option>
      <option value="10">10</option>
      <option value="11">11</option>
      <option value="12">12</option>
      <option value="13">13</option>
      <option value="14">14</option>

    </select>
    <button class="bu2">下一页</button>
  </div>

  <div class="bot">
    <span>登入</span>
    <span>注册</span>
    <span>返回顶部</span>
  </div>

  <span class="papa">手机app下载</span><span class="pp1">万峰智慧商城手机版 -- 掌上比价平台</span>
  <span class="pp2">chast.vip.8081/.com</span>


  <script>




    var bu1 = document.querySelector('.bu1')
    var bu2 = document.querySelector('.bu2')
    var ko = document.querySelector('.ko')
    var select1 = document.querySelector('select')

    //    下拉框请求页面
    $('select').change(function (e) {
      var e = e || event

      var nu = e.target.value


      let xhr2 = new XMLHttpRequest()
      xhr2.open('get', `http://chst.vip:1234/api/getmoneyctrl?pageid=${nu}`, true,)
      xhr2.onload = function () {

        if (xhr2.status === 200) {
          var res = JSON.parse(xhr2.responseText)
          //  console.log(res.result)
          let regExp = /^<[^<]+\s+src="([^''""]*)"/;

          var lis = ''

          res.result.forEach(function (sso, indd) {
            let tu = res.result[indd].productImgSm.match(regExp)[1].split('=')[2];
            //  console.log(tu)
            lis += `
                <li>
              <img src="${tu}">
              <h4>${sso.productName}<span class="ss">${sso.productPinkage}</span></h4>
              <div class="di">${sso.productFrom}</div>
              <span class="s">${sso.productTime}</span>
             
              <div class="di2">${sso.productComCount}</div>

         </li>
              `
          })
        }
        ko.innerHTML = lis

        localStorage.setItem('pageid', nu)



      }
      xhr2.send()


    })
    //  点击下一页....................................................................................................

    bu2.onclick = function () {

      var num = +localStorage.getItem('pageid')

      num +=1
      // console.log(num)

      if (num >=14) {
        num = 14
        $('select option').attr('selected', false)
   
      }


      $('select option').eq(`${num-1}`).attr('selected', true)

      // var options=$('select option:selected').val()
      //  console.log(options)

      //  $('select').find(`option[value=${num}]`).attr('selected', true)

      let xhr2 = new XMLHttpRequest()
      xhr2.open('get', `http://chst.vip:1234/api/getmoneyctrl?pageid=${num}`,false)
      xhr2.onload = function () {

        if (xhr2.status === 200) {
          var res = JSON.parse(xhr2.responseText)
          // console.log(res.result)
          let regExp = /^<[^<]+\s+src="([^''""]*)"/;

          var lis = ''

          res.result.forEach(function (sso, indd) {
            let tu = res.result[indd].productImgSm.match(regExp)[1].split('=')[2];
            // console.log(tu)
            lis += `
           <li>
         <img src="${tu}">
         <h4>${sso.productName}<span class="ss">${sso.productPinkage}</span></h4>
         <div class="di">${sso.productFrom}</div>
         <span class="s">${sso.productTime}</span>
        
         <div class="di2">${sso.productComCount}</div>

    </li>
         `
          })
        localStorage.setItem('pageid', num)

        }
        ko.innerHTML = lis



      }
      xhr2.send()

    }



    //  点击上一页.........................................................................................

    bu1.onclick = function () {
     

      var num = +localStorage.getItem('pageid')
      $('select option').eq(num).siblings().attr('selected', false)

      num -=1
      // console.log(num)
      if (num <=0) {
        num = 1


      }
      $('select option').eq(`${num-1}`).attr('selected', true)

      // $('select').find(`option[value=${num}]`).attr('selected', true)


       // var options=$('select option:selected').val()
      //  console.log(options)

      let xhr2 = new XMLHttpRequest()
      xhr2.open('get', `http://chst.vip:1234/api/getmoneyctrl?pageid=${num-1}`,true)
      xhr2.onload = function () {

        if (xhr2.status === 200) {
          var res = JSON.parse(xhr2.responseText)
          // console.log(res.result)
          let regExp = /^<[^<]+\s+src="([^''""]*)"/;

          var lis = ''

          res.result.forEach(function (sso, indd) {
            let tu = res.result[indd].productImgSm.match(regExp)[1].split('=')[2];
            // console.log(tu)
            lis += `
             <li>
           <img src="${tu}">
           <h4>${sso.productName}<span class="ss">${sso.productPinkage}</span></h4>
           <div class="di">${sso.productFrom}</div>
           <span class="s">${sso.productTime}</span>
          
           <div class="di2">${sso.productComCount}</div>
  
            </li>
           `
          })
        localStorage.setItem('pageid', num)

        }
        ko.innerHTML = lis



      }
      xhr2.send()

    }

    // 首次请求页面..........................................................................................................

    //    var ko=document.querySelector('.ko')
    let xhr1 = new XMLHttpRequest()
    xhr1.open('get', `http://chst.vip:1234/api/getmoneyctrl?pageid=0`, true,)
    xhr1.onload = function () {

      if (xhr1.status === 200) {
        var res2 = JSON.parse(xhr1.responseText)
        //  console.log(res2.result)
        let regExp = /^<[^<]+\s+src="([^''""]*)"/;

        var lis2 = ''

        res2.result.forEach(function (so, ind) {
          let tu = res2.result[ind].productImgSm.match(regExp)[1].split('=')[2];
          //  console.log(tu)
          lis2 += `
                <li productid="${so.productId}"">
              <img src="${tu}">
              <h4>${so.productName}<span class="ss">${so.productPinkage}</span></h4>
              <div class="di">${so.productFrom}</div>
              <span class="s">${so.productTime}</span>
             
              <div class="di2">${so.productComCount}</div>

         </li>
                        
                     
                  
               `
        })
      }
      ko.innerHTML = lis2


      localStorage.setItem('pageid', 1)

    //   $('li').click(function(){
    //         location.href="./超值折扣推荐详情页.html"
    //       })
    $('li').click(function(e){

        
var e=e||window.event
var target=e.target||e.srcElement

 if(target.nodeName==="LI"){

     localStorage.setItem("productid",target.getAttribute('productid'))
   

 }
 else{
     localStorage.setItem("productid",target.parentNode.getAttribute('productid'))
 
     
 }
 location.href="./超值折扣推荐详情页.html"

 })



    }



          xhr1.send()


          var ding = document.querySelector('.bot span:nth-of-type(3)')

          ding.style.color = '#c36'
          ding.onclick = function () {
            document.documentElement.scrollTop = 0
          }

          $('.back').click(function(){
            location.href="./商品首页.html"
          })

       

  



  </script>
</body>




</html>